package com.grace.cms.forum.user.controller.user;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.grace.cms.common.domain.entity.CmsLookRecord;
import com.grace.cms.common.enums.CommonVisibleEnums;
import com.grace.cms.common.enums.RecordTypeEnums;
import com.grace.cms.common.model.param.WebRecordParam;
import com.grace.cms.forum.record.domain.CmsCollectRecord;
import com.grace.cms.forum.record.domain.CmsLikeRecord;
import com.grace.cms.forum.record.domain.CmsNastyRecord;
import com.grace.cms.forum.record.domain.CmsScoreRecord;
import com.grace.cms.forum.record.domain.CmsShareRecord;
import com.grace.cms.forum.record.service.impl.CmsRecordServiceImpl;
import com.grace.cms.forum.user.service.impl.HandRecordServiceImpl;
import com.grace.common.config.GraceConfig;
import com.grace.common.core.controller.BaseController;
import com.grace.common.core.domain.AjaxResult;
import com.grace.common.core.page.TableDataInfo;
import com.grace.system.utils.SecurityUtils;

@Controller
public class UserRecord extends BaseController {

    @Autowired
    private CmsRecordServiceImpl recordService;

    @Autowired
    private HandRecordServiceImpl handRecordService;

    /**
     * 用户浏览记录
     * @return
     */
    @GetMapping(value = {"/{themeName}/user/listLook/{lookType}","/{themeName}/user/listLook"})
    @ResponseBody
    public TableDataInfo listLookRecord( @PathVariable("themeName") String themeName,@PathVariable(value="lookType" ,required = false) RecordTypeEnums lookType) {
        CmsLookRecord cmsLookRecord = new CmsLookRecord();
        cmsLookRecord.setThemeName(themeName);
        cmsLookRecord.setOnlyCode(GraceConfig.getOnlyCode());
        cmsLookRecord.setCreateBy(SecurityUtils.getUsername());
        cmsLookRecord.setVisible(CommonVisibleEnums.SHOW.ordinal());
        if(lookType!=null){
            cmsLookRecord.setRecordType(lookType.ordinal());
        }
        startPage();
        List<CmsLookRecord> list = recordService.listLookRecord(cmsLookRecord);
        return getDataTable(list);
    }

    /**
     * 获取用户收藏记录
     * @return
     */
    @GetMapping(value = {"/{themeName}/user/listCollect","/{themeName}/user/listCollect/{recordType}"})
    @ResponseBody
    public TableDataInfo listCollectRecord( @PathVariable("themeName") String themeName,@PathVariable(value="recordType" ,required = false) RecordTypeEnums recordType) {
        CmsCollectRecord recordParam = new CmsCollectRecord();
        recordParam.setThemeName(themeName);
        recordParam.setOnlyCode(GraceConfig.getOnlyCode());
        recordParam.setCreateBy(SecurityUtils.getUsername());
        recordParam.setVisible(CommonVisibleEnums.SHOW.ordinal());
        if(recordType!=null){
            recordParam.setRecordType(recordType.ordinal());
        }
        startPage();
        List<CmsCollectRecord> list = recordService.listCollectRecord(recordParam);
        return getDataTable(list);
    }

     /**
     * 获取用户喜欢记录
     * @return
     */
    @GetMapping(value = {"/{themeName}/user/listLike","/{themeName}/user/listLike/{recordType}"})
    @ResponseBody
    public TableDataInfo listLikeRecord( @PathVariable("themeName") String themeName,@PathVariable(value="recordType" ,required = false) RecordTypeEnums recordType) {
        CmsLikeRecord recordParam = new CmsLikeRecord();
        recordParam.setThemeName(themeName);
        recordParam.setOnlyCode(GraceConfig.getOnlyCode());
        recordParam.setCreateBy(SecurityUtils.getUsername());
        recordParam.setVisible(CommonVisibleEnums.SHOW.ordinal());
        if(recordType!=null){
            recordParam.setRecordType(recordType.ordinal());
        }
        startPage();
        List<CmsLikeRecord> list = recordService.listLikeRecord(recordParam);
        return getDataTable(list);
    }

    /**
     * 获取用户讨厌记录
     * @return
     */
    @GetMapping(value = {"/{themeName}/user/listNasty","/{themeName}/user/listNasty/{recordType}"})
    @ResponseBody
    public TableDataInfo listNastyRecord( @PathVariable("themeName") String themeName,@PathVariable(value="recordType" ,required = false) RecordTypeEnums recordType) {
        CmsNastyRecord recordParam = new CmsNastyRecord();
        recordParam.setThemeName(themeName);
        recordParam.setOnlyCode(GraceConfig.getOnlyCode());
        recordParam.setCreateBy(SecurityUtils.getUsername());
        recordParam.setVisible(CommonVisibleEnums.SHOW.ordinal());
        if(recordType!=null){
            recordParam.setRecordType(recordType.ordinal());
        }
        startPage();
        List<CmsNastyRecord> list = recordService.listNastyRecord(recordParam);
        return getDataTable(list);
    }

    /**
     * 获取用户评分记录
     * @return
     */
    @GetMapping(value = {"/{themeName}/user/listScore","/{themeName}/user/listScore/{recordType}"})
    @ResponseBody
    public TableDataInfo listScoreRecord( @PathVariable("themeName") String themeName,@PathVariable(value="recordType" ,required = false) RecordTypeEnums recordType) {
        CmsScoreRecord recordParam = new CmsScoreRecord();
        recordParam.setThemeName(themeName);
        recordParam.setOnlyCode(GraceConfig.getOnlyCode());
        recordParam.setCreateBy(SecurityUtils.getUsername());
        recordParam.setVisible(CommonVisibleEnums.SHOW.ordinal());
        if(recordType!=null){
            recordParam.setRecordType(recordType.ordinal());
        }
        startPage();
        List<CmsScoreRecord> list = recordService.listScoreRecord(recordParam);
        return getDataTable(list);
    }

    /**
     * 获取用户分享记录
     * @return
     */
    @GetMapping(value = {"/{themeName}/user/listShare","/{themeName}/user/listShare/{recordType}"})
    @ResponseBody
    public TableDataInfo listShareRecord( @PathVariable("themeName") String themeName,@PathVariable(value="recordType" ,required = false) RecordTypeEnums recordType) {
        CmsShareRecord recordParam = new CmsShareRecord();
        recordParam.setThemeName(themeName);
        recordParam.setOnlyCode(GraceConfig.getOnlyCode());
        recordParam.setCreateBy(SecurityUtils.getUsername());
        recordParam.setVisible(CommonVisibleEnums.SHOW.ordinal());
        if(recordType!=null){
            recordParam.setRecordType(recordType.ordinal());
        }
        startPage();
        List<CmsShareRecord> list = recordService.listShareRecord(recordParam);
        return getDataTable(list);
    }
    /**
     * 移除用户记录
     * @return
     */
    @PostMapping("/{themeName}/user/removeRecord/{recordId}")
    @ResponseBody
    public AjaxResult removeRecord( @PathVariable("themeName") String themeName,@PathVariable(value="recordId") String recordId) {
        WebRecordParam recordParam = new WebRecordParam();
        recordParam.setRecordId(recordId);
        recordParam.setThemeName(themeName);
        recordParam.setOnlyCode(GraceConfig.getOnlyCode());
        recordParam.setCreateBy(SecurityUtils.getUsername());
        recordParam.setVisible(CommonVisibleEnums.DELETE.ordinal());
        RecordTypeEnums recordType = RecordTypeEnums.getRecordType(recordId);
        return success(handRecordService.updateCmsRecord(recordParam,recordType));
    }

    /**
     * 移除用户浏览记录
     * @return
     */
    @GetMapping("/{themeName}/user/removeLook/{lookId}")
    @ResponseBody
    public AjaxResult removeLookPage( @PathVariable("themeName") String themeName,@PathVariable(value="lookId" ,required = false) Long lookId) {
        CmsLookRecord recordParam = new CmsLookRecord();
        recordParam.setLookId(lookId);
        recordParam.setVisible(CommonVisibleEnums.DELETE.ordinal());
        recordParam.setCreateBy(SecurityUtils.getUsername());
        return success(handRecordService.updateCmsLookRecord(recordParam));
    }


    
}
